﻿#include "FITKSpectraAbstractPower.h"
#include "FITKSpectraAlgorithm.h"

namespace Acoustics
{
    FITKSpectraAbstractPower::FITKSpectraAbstractPower()
    {
        //构造
    }

    FITKSpectraAbstractPower::~FITKSpectraAbstractPower()
    {
        //销毁
    }

    void FITKSpectraAbstractPower::copy(FITKAcousticsAbstractSpectra * copyData)
    {
        FITKSpectraAbstractPower* subCopyData = dynamic_cast<FITKSpectraAbstractPower*>(copyData);
        if (copyData == nullptr || subCopyData == nullptr)return;
        FITKAcousticsAbstractSpectra::copy(copyData);
        _dBEnableState = subCopyData->getDBEnableState();
        _aWeightingEnableState = subCopyData->getAWeightingEnableState();
        _dBUserCoefficient = subCopyData->getDBDefaultCoefficient();
        _formCalcType = subCopyData->getFormCalcType();
    }

    void FITKSpectraAbstractPower::setDBEnableState(bool enableState)
    {
        //设置dB计算的启用状态
        _dBEnableState = enableState;
    }

    bool FITKSpectraAbstractPower::getDBEnableState()
    {
        //获取dB计算的启用状态
        return _dBEnableState;
    }

    double FITKSpectraAbstractPower::getDBDefaultCoefficient()
    {
        //获取dB的默认系数 - 需要基类里实现
        return 0.0;
    }

    void FITKSpectraAbstractPower::setDBUserCoefficient(double coeff)
    {
        _dBUserCoefficient = coeff;
    }

    double FITKSpectraAbstractPower::getDBUserCoefficient()
    {
        return _dBUserCoefficient;
    }

    bool FITKSpectraAbstractPower::isDBUserDefined()
    {
        if (_dBUserCoefficient > 0)return true;
        return false;
    }

    void FITKSpectraAbstractPower::setAWeightingEnableState(bool enableState)
    {
        _aWeightingEnableState = enableState;
    }

    bool FITKSpectraAbstractPower::getAWeightingEnableState()
    {
        return _aWeightingEnableState;
    }

    void FITKSpectraAbstractPower::setFormCalcType(int type)
    {
        _formCalcType = type;
    }

    int FITKSpectraAbstractPower::getFormCalcType()
    {
        return _formCalcType;
    }

    QList<SpectraValue> FITKSpectraAbstractPower::getRealSpectraValue()
    {
        FITKSpectraAlgorithm* spectraAlg = this->getSpectraAlg();
        if (!spectraAlg) return QList<SpectraValue>();
        spectraAlg->setDBAlgConfig(_dBEnableState, _dBUserCoefficient);
        spectraAlg->setAWeighting(_aWeightingEnableState);
        spectraAlg->setCalcType(_formCalcType);
        if (!spectraAlg->startCalc(true)) return QList<SpectraValue>();
        return spectraAlg->getResults();
    }
}
